package com.wbcs.system.buttons;

import java.util.List;

import com.wbcs.config.component.IComponentConfigBean;
import com.wbcs.config.component.application.report.ReportBean;
import com.wbcs.system.ReportRequest;
import com.wbcs.system.component.application.report.configbean.editablereport.EditableReportSqlBean;
import com.wbcs.util.Consts_Private;

public class DeleteButton extends AbsEditableReportButton
{
    public DeleteButton(IComponentConfigBean ccbean)
    {
        super(ccbean);
    }

    @Override
	public String getButtonType()
    {
        return Consts_Private.DELETE_BUTTON;
    }

    @Override
	protected String getClickEvent(ReportRequest rrequest,String paramsForGetUrl)
    {
        StringBuffer paramsBuf=new StringBuffer();
        paramsBuf.append("{pageid:'").append(ccbean.getPageBean().getId()).append("'");
        ReportBean rbean=(ReportBean)this.ccbean;
        EditableReportSqlBean ersqlbean=(EditableReportSqlBean)rbean.getSbean().getExtendConfigDataForReportType(EditableReportSqlBean.class);
        if(ersqlbean==null) return "";
        paramsBuf.append(",savingReportIds:[");
        paramsBuf.append("{reportid:'").append(ccbean.getId()).append("',updatetype:'delete'}");
        List<ReportBean> lstBindedReportBeans=(List<ReportBean>)rrequest.getAttribute(ccbean.getId()+"_DYN_BINDED_REPORTS");
        if(lstBindedReportBeans==null||lstBindedReportBeans.size()==0)
        {
            lstBindedReportBeans=ersqlbean.getLstDeleteBindingReportBeans();
        }
        if(lstBindedReportBeans!=null&&lstBindedReportBeans.size()>0)
        {
            for(ReportBean rbBindedTmp:lstBindedReportBeans)
            {
                paramsBuf.append(",{reportid:'").append(rbBindedTmp.getId()).append("',updatetype:'delete'}");
            }
        }
        paramsBuf.append("]}");
        rrequest.removeAttribute(ccbean.getId()+"_DYN_BINDED_REPORTS");
        return "saveEditableReportData("+paramsBuf.toString()+")";
    }
}
